<?php
	session_start();
	
//	print_r($_POST);
	require_once('../../lib/'.'BaseDir.inc.htm');
	require_once (EIU_LIB.'View.class.htm');
	require_once('../../lib/'.'DBCommon.class.htm');
	require_once (EIU_CLASS.'BaseClass.htm');
	
	if(isset($_POST['page']) && !empty($_POST['page']))
	{
		$startLimit = ($_POST['page']-1)*10;
		$endLimit = 10;
	}
	
	$condition = "`isDeleted`=0";
	if(isset($_POST['suppID']) && !empty($_POST['suppID']))
	{
		$condition .= " AND `SuppName` LIKE '%".$_POST['suppID']."%'";
	}
	if(isset($_POST['invcNo']) && !empty($_POST['invcNo']))
	{
		$condition .= " AND `InvcNo` LIKE '%".$_POST['invcNo']."%'";
	}
	if((isset($_POST['fromDate']) && !empty($_POST['fromDate']))&&(isset($_POST['toDate']) && !empty($_POST['toDate'])))
	{
		$FromDate = changeDateFormat($_POST["fromDate"],"words2num");
		$ToDate = changeDateFormat($_POST["toDate"],"words2num");
		$condition .= " AND Date(InvcDate) between '".$FromDate."'AND'".$ToDate."'";
	}
	$condition .=  " ORDER BY `InvcDate` DESC";
	
//	print_r($condition);
	$oDB = new DBCommon();
	$conn =  $oDB->stl_openConn();
	
	$count = "SELECT COUNT(*) as count FROM `invoice_tbl` WHERE `isDeleted`=0 AND ".$condition;
	$rs_count = $oDB->stl_db_select($count, $conn);
	if(!empty($rs_count[0]->count)){
		$data1["Count"] = (int)$rs_count[0]->count;
	}
	if(isset($_POST['page']) && !empty($_POST['page']))
	{
		$condition .= " LIMIT ".$startLimit.",".$endLimit;
	}
	$rs_select_room = selectALlTable("*","`invoice_tbl`",$condition);
	
	if(is_array($rs_select_room))
	{
		$i=0;
		foreach($rs_select_room as $key=>$value)
		{
			$data1['Result'][$i]['invcID']		=	$rs_select_room[$key]->InvcID;
			$data1['Result'][$i]['invcNo']		=	$rs_select_room[$key]->InvcNo;
			$data1['Result'][$i]['suppID']		=	$rs_select_room[$key]->SuppID;
			$data1['Result'][$i]['suppName']	=	$rs_select_room[$key]->SuppName;
			$data1['Result'][$i]['VATAmount']	=	$rs_select_room[$key]->VATAmount;
			$data1['Result'][$i]['beforeVAT']	=	$rs_select_room[$key]->BeforeVATAmount;
			$data1['Result'][$i]['afterVAT']	=	$rs_select_room[$key]->AfterVATAmount;
			$data1['Result'][$i]['invcDate']		=	changeDateFormat($rs_select_room[$key]->InvcDate,"");
			$data1['Result'][$i]['invcImage']	=	$rs_select_room[$key]->InvcImage;
			$data1['Result'][$i]['despt']		=	$rs_select_room[$key]->Description;
			
			$i++;
		}
		echo json_encode($data1);
	}else{
		echo 'NG';
	}
	
	$oDB->stl_closeConn($conn);
	
?>
